package com.xian.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xian.common.annotation.Log;
import com.xian.common.core.controller.BaseController;
import com.xian.common.core.domain.AjaxResult;
import com.xian.common.enums.BusinessType;
import com.xian.manage.domain.Poetry;
import com.xian.manage.service.IPoetryService;
import com.xian.common.utils.poi.ExcelUtil;
import com.xian.common.core.page.TableDataInfo;

/**
 * 诗词精选Controller
 * 
 * @author Hanys
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/manage/poetry")
public class PoetryController extends BaseController
{
    @Autowired
    private IPoetryService poetryService;

    /**
     * 查询诗词精选列表
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:list')")
    @GetMapping("/list")
    public TableDataInfo list(Poetry poetry)
    {
        startPage();
        List<Poetry> list = poetryService.selectPoetryList(poetry);
        return getDataTable(list);
    }

    /**
     * 导出诗词精选列表
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:export')")
    @Log(title = "诗词精选", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Poetry poetry)
    {
        List<Poetry> list = poetryService.selectPoetryList(poetry);
        ExcelUtil<Poetry> util = new ExcelUtil<Poetry>(Poetry.class);
        util.exportExcel(response, list, "诗词精选数据");
    }

    /**
     * 获取诗词精选详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(poetryService.selectPoetryById(id));
    }

    /**
     * 新增诗词精选
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:add')")
    @Log(title = "诗词精选", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Poetry poetry)
    {
        return toAjax(poetryService.insertPoetry(poetry));
    }

    /**
     * 修改诗词精选
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:edit')")
    @Log(title = "诗词精选", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Poetry poetry)
    {
        return toAjax(poetryService.updatePoetry(poetry));
    }

    /**
     * 删除诗词精选
     */
    @PreAuthorize("@ss.hasPermi('manage:poetry:remove')")
    @Log(title = "诗词精选", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(poetryService.deletePoetryByIds(ids));
    }
}
